function setup() {
	// auto.waitFor();
	console.show();
}
setup();

function step_立即参与() {
	log("点击 立即参与");
	click(550, 1730);
	sleep(2000);
}
function step_wait_去学习() {
	var cnt = 1;
	while (true) {
		if (cnt++ > 3) {
			log("不等了\n直接开始滑动");
			break;
		}
		if (text("十七散人").findOne(500)) {
			log("找到了，说明加载完毕");
			break;
		}
	}
}
function step_去学习() {
	log("点击 去学习");
	click(500, 1600);
	sleep(2000);
}
function step_wait_开始学习() {
	var cnt = 0;
	while (true) {
		if (cnt++ > 10) {
			log("不等了\n开始学习");
			break;
		}
		if (clickable(true).findOne(500)) {
			log("找到了，说明加载完毕");
			break;
		}
	}
}
function step_找到选择题() {
	log("Here 44");
	// var parent = id("dp5").findOne(1000);
	var parent = clickable(true).find();
	// log(parent);
	if (parent !== null) {
		// log(parent.childCount()); // 1
		// log(parent.child(0).childCount()); // 2
		// log(parent.child(0).child(0).childCount()); // 1
		// log(parent.child(0).child(0).child(0).childCount()); // 2
		// log(parent.child(0).child(0).child(0).child(0).childCount()); // ?
		// log(parent.child(0).child(0).child(0).child(1).childCount()); // ?
		log(parent.length);
		var list = new Array();
		for (var i = 0; i < parent.length; i++) {
			log(i + ": " + parent[i].bounds());
			list.push(parent[i].bounds());
		}
		console.hide();
		list.forEach((rect, i) => {
			toastLog(
				i + " :: " + rect.left + " :: " + rect.right + " :: " + rect.centerY()
			);
			// swipe(540, 400, rect.centerX(), rect.centerY(), 2000);
			if (rect.left < device.width / 5) {
				sleep(2000);
			} else {
				swipe(rect.left, rect.centerY(), rect.right, rect.centerY(), 2000);
				sleep(500);
			}
			/**
			 * 可以看出
			 * 0 是确认选择
			 * 1 2 3 4 分别是 A B C D
			 * 6 是继续听讲
			 */
		});
		console.show();
	} else {
		log("找不到 parent");
	}
	log("Here 45");
	sleep(1e7);
	console.hide();
	exit();
}
function step_core() {
	// auto.waitFor();
	// console.hide();
	console.show();
	do {
		var parent = clickable(true).find();
		toastLog("正在等待出现选择题...");
		sleep(5000);
	} while (parent === null);

	toastLog("似乎找到选择题: " + parent.length);
	// setTimeout(() => {}, 2000);
	sleep(2000);
	var list = new Array();
	for (var i = 0; i < parent.length; i++) {
		log(i + ": " + parent[i].bounds());
		list.push(parent[i].bounds());
	}
	console.show();
	list.forEach((rect, i) => {
		log(i + " :: " + rect.left + " :: " + rect.right + " :: " + rect.centerY());
		// swipe(540, 400, rect.centerX(), rect.centerY(), 2000);
		// swipe(rect.left, rect.centerY(), rect.right, rect.centerY(), 2000);
	});
	log("选择 A项");
	click(list[1].centerX(), list[1].centerY());
	sleep(500);
	log("选择 确定");
	click(list[0].centerX(), list[0].centerY());
	// console.show();
	console.hide();
	exit();
}
step_找到选择题();
